package com.ruoyi.web.controller.open;

import com.ruoyi.common.core.domain.model.LoginDTO;
import com.ruoyi.framework.web.service.SysLoginService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author wux
 * @date 2023/7/11 14:46
 */
@RestController
@RequestMapping("/client/open")
public class ForeignOpenClient {
    @Autowired
    private SysLoginService sysLoginService;

    /**
     * 网关登录验证
     * @param params
     * @return
     */
    @PostMapping("/login")
    public ResultDevice login(@Valid @RequestBody LoginDTO params) {
        // 生成令牌
        params.setChannel(2);
        try {
            String token = sysLoginService.login(params);
            return ResultDevice.ok(token, 30 * 60);
        } catch (Exception e) {
            return ResultDevice.error(1);
        }
    }

    /**
     * 生产记录上传
     * @param params
     * @return
     */
    @PostMapping("/up/prodRecord")
    public ResultDevice login(@RequestBody String params, @RequestHeader("token") String token) {
        if(StringUtils.isBlank(token)){
            return ResultDevice.error(1);
        }
        // 生成令牌
        System.out.println(params);
        return ResultDevice.ok();
    }

}
